import { Define, EntityObjectFactory } from 'tiny-entity2';
const EntityObjectType = EntityObjectFactory.GetEntityObjectType(process.env.dataBaseType || 'mysql');
import { StoreConfig } from './storeConfig';
import { ImageStore } from './imageStore';
import { StoreExtension } from './storeExtension';

@Define.Table({ TableName: 'store' })
export class Store extends EntityObjectType<Store> {
    @Define.PrimaryKey()
    id: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        DataLength: 32,
        IsIndex: true,
        NotAllowNULL: true
    })
    userId: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        NotAllowNULL: true
    })
    userName: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        NotAllowNULL: true
    })
    name: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    address: string;

    /**
     * 经度
     *
     * @type {string}
     * @memberof Store
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    longitude?: string;

    /**
     * 纬度
     *
     * @type {string}
     * @memberof Store
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    latitude?: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    description: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        DefaultValue: 'normal'
    })
    status: string;

    @Define.Column({ DataType: Define.DataType.INT, DataLength: 1, DefaultValue: false })
    isDefault: boolean;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        DefaultValue: 'single'
    })
    type: string;


    @Define.Column({
        DataType: Define.DataType.BIGINT
    })
    createTime: number;

    @Define.Column({
        DataType: Define.DataType.BIGINT
    })
    version: number;

    @Define.Mapping({
        Mapping: 'StoreConfig',
        MappingKey: { FKey: 'storeId', MKey: 'id' },
        MappingType: Define.MappingType.One
    })
    storeConfig: StoreConfig;

    @Define.Mapping({
        Mapping: 'StoreExtension',
        MappingKey: { FKey: 'storeId', MKey: 'id' },
        MappingType: Define.MappingType.One
    })
    storeExtension: StoreExtension;

    @Define.Mapping({
        Mapping: 'ImageStore',
        MappingKey: { FKey: 'objectId', MKey: 'id' }
    })
    images: ImageStore[];

    chainStoreId?: string;
}

export const StoreStatus = {
    Normal: 'normal',
}

export const StoreType = {
    Single: 'single',
    Chain: 'chain'
}